<!--
 * @Author: zheguo 3188606474@qq.com
 * @Date: 2024-04-23 14:29:32
 * @LastEditors: zheguo 3188606474@qq.com
 * @LastEditTime: 2024-04-24 23:12:57
 * @FilePath: \projectOne\myapp\src\views\DetailView.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="detail_content">
    <div class="content_navbar">
      <div class="navbar_son">

        <div class="son_one" v-for="data in datalist" :key="data">
          <p>{{ data.title }}</p>
        </div>
        <div class="son_two">
          <p>概述页</p>
          <p>参数页</p>
          <p>F码通道</p>
          <p>咨询客服</p>
          <p>用户评价</p>
        </div>
      </div>
    </div>
    <ul v-for="data in datalist" :key="data">

      <div class="block text-center" m="t-4">
        <el-carousel trigger="click" width="1200px" height="560px">
          <el-carousel-item v-for="item in data.swiperImg" :key="item">
            <img :src="item.img" alt="" style="width: 100%;height: 100%;">
          </el-carousel-item>
        </el-carousel>
      </div>

      <li class="detail_text">
        <div class="detail_one">
          <p style="font-weight: 500">{{ data.title }}</p>
          <p style="font-size: 15px;color: #9b9999">{{ data.text }}</p>
          <p style="font-size: 16px;color: #ff6700">小米自营</p>
          <p style="font-size: 20px;color: #ff6700">{{ data.price }}元</p>
        </div>
        <div class="detail_two">
          <div>
            {{ data.giveaway }}
          </div>
        </div>

        <div class="choice_version">
          <p>选择版本</p>
          <div class="option_version">
            <div v-for="(key, index) in data.version" :key="key" @click="handleColorone(index)"
                 :class="isVersion == index ? 'active' : ''">{{
                key
              }}
            </div>
          </div>
        </div>

        <div class="choice_color">
          <p>选择颜色</p>
          <div class="option_color">
            <div v-for="(color, index) in data.color" :key="color" @click="handleColorTwo(index)"
                 :class="isColor == index ? 'active' : ''">
              {{ color }}
            </div>
          </div>
        </div>

        <div class="detail_joinCar">
          <button class="joinCar">加入购物车</button>
          <button class="like">
            <i class="iconfont icon-aixin_shixin"></i> 喜欢
          </button>
        </div>

      </li>

    </ul>
  </div>
</template>
<script>
import axios from 'axios'

export default {
  data() {
    return {
      datalist: [],
      isColor: -1,
      isVersion: -1
    }
  },
  async created() {
    await axios.get("../../json/xiaomiData.json").then(res => {

      for (var i = 0; i < res.data.data.length; i++) {
        var result = res.data.data[i].content.filter(item => item.filterId == this.$route.params.myid)
        if (result.length) {
          this.datalist = result
        }
      }
    })
  },
  methods: {
    handleColorone(index) {
      this.isVersion = index
    },
    handleColorTwo(index) {
      this.isColor = index
    },
    scrolling() {
      // 滚动条距文档顶部的距离
      // let scrollTop =
      //     document.documentElement.scrollTop ||
      //     document.body.scrollTop;
      // // 滚动条滚动的距离
      // // let scrollStep = scrollTop - this.oldScrollTop;
      // console.log("header 滚动距离 ", scrollTop);


      window.scrollTo({
        top: 138,
        left: 0,
        behavior: "smooth"
      });
      // // 更新——滚动前，滚动条距文档顶部的距离
      // this.oldScrollTop = scrollTop;

      // //变量windowHeight是可视区的高度
      // let windowHeight =
      //     document.documentElement.clientHeight || document.body.clientHeight;
      // //变量scrollHeight是滚动条的总高度
      // let scrollHeight =
      //     document.documentElement.scrollHeight || document.body.scrollHeight;

      //滚动条到底部的条件
      // if (scrollTop + windowHeight == scrollHeight) {
      //     //你想做的事情
      //     console.log("header  你已经到底部了");
      // }
      // if (scrollStep < 0) {
      //     console.log("header 滚动条向上滚动了！");
      // } else {
      //     console.log("header  滚动条向下滚动了！");
      // }
      // // 判断是否到了最顶部
      // if (scrollTop <= 0) {
      //     console.log("header 到了最顶部")
      // }
    }
  },
  beforeMount() {
    //    addEventListener("scroll",this.scrolling)
    window.scrollTo({
      top: 138,
      left: 0,
      behavior: "smooth"
    });
    // var scrollTop =
    //     document.documentElement.scrollTop ||
    //     document.body.scrollTop;

    // var timer = setInterval(() => {
    //     if (scrollTop !== '138') {
    //         scrollTop++
    //     } else {
    //         clearInterval(timer)
    //     }
    // }, 10)
  }

}
</script>
<style lang="scss" scoped>
.active {
  border: 1px solid orangered !important;
  color: orangered;
}

.detail_content {
  width: 100%;
  border-top: 1px solid #ccc;

  .content_navbar {
    width: 100%;
    box-shadow: 0px 4px 8px #ccc;

    .navbar_son {
      width: 1200px;
      height: 60px;
      margin: 0 auto;

      .son_one {
        float: left;
        width: 500px;
        display: flex;

        p {
          height: 60px;
          line-height: 30px;
        }
      }

      .son_two {
        float: right;
        width: 400px;
        height: 60px;
        display: flex;
        justify-content: space-between;
        align-items: center;

        p {
          list-style: none;
          height: auto;
          cursor: pointer;
          line-height: 30px;
        }

      }
    }
  }

  ul {
    list-style: none;
    width: 1200px;
    margin: 0 auto;
    display: flex;

    .text-center {
      margin-right: 20px;
      width: 110%;
      height: 560px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .detail_text {
      width: 100%;

      .detail_one {
        margin: 30px 0;

        p {
          font-size: 20px;
        }

      }

      .detail_two {
        margin-top: 28px;
        width: 100%;
        border-top: 1px solid #ccc;

        div {
          width: 100px;
          color: orangered;
          text-align: center;
        }
      }

      .choice_version {
        p {
          font-size: 20px;
          font-weight: 500;
          border-bottom: 0px;
        }

        .option_version {
          width: 100%;
          height: auto;
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;


          div {
            width: 49%;
            height: 50px;
            margin-top: 10px;
            border: 1px solid #ccc;
            cursor: pointer;
            line-height: 50px;
            font-size: 20px;
            text-align: center;
            font-weight: 300;
          }

          div:hover {
            border: 1px solid orangered;
            color: orangered;
          }


        }
      }

      .choice_color {
        p {
          font-size: 20px;
          font-weight: 500;
          border-bottom: 0px;
        }

        .option_color {
          width: 100%;
          height: auto;
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;


          div {
            width: 49%;
            height: 50px;
            margin-top: 10px;
            border: 1px solid #ccc;
            cursor: pointer;
            line-height: 50px;
            font-size: 20px;
            text-align: center;
            font-weight: 300;

          }

          div:hover {
            border: 1px solid orangered;
            color: orangered;
          }

        }

      }

      .detail_joinCar {
        width: 100%;
        height: 50px;
        display: flex;
        justify-content: start;
        align-items: center;
        margin: 20px 0;

        .joinCar {
          width: 300px;
          border: none;
          height: 50px;
          cursor: pointer;
          text-align: center;
          font-size: 20px;
          font-weight: 500;
          color: white;
          background-color: #ff6700;
        }

        button:hover {
          opacity: 0.8;
        }

        .like {
          width: 150px;
          margin-left: 10px;
          border: none;
          height: 50px;
          cursor: pointer;
          text-align: center;
          font-size: 20px;
          font-weight: 500;
          color: white;
          background-color: #cccccc;

        }
      }
    }
  }
}
</style>